const app = getApp()
Page({
  data: {
    value: '',
    hosList: [],
    show: false,
    actions: [
      {
        name: '使用卡密激活',
      },
      {
        name: '后台已开通工种,去关联手机号',
        /**subname: '立即绑定',**/
      }
      /** 
      {
        name: '微信支付',
        subname: '暂未开通',
        disabled: true
      },
      **/
    ],
  },
  onClose() {
    this.setData({ show: false });
  },

  onSelect(event) {
    console.log(event.detail);
    if("使用卡密激活" == event.detail.name){
        this.setData({ show: false });
        wx.navigateTo({
          url: "/pages/activation/activation"
        });

    }else if("后台已开通工种,去关联手机号" == event.detail.name){
      wx.navigateTo({
        url: "../binding/binding"
      });
    }
    
    else if("微信支付" == event.detail.name){
      console.log('==zaixian====');
    }
    
  },
  onCancel() {
    this.setData({ show: false });
  },
  
  onShow: function () {
    this.setData({ 
      hosList: [] ,
      value: ''
    });
  },
  onChange(e) {
    this.setData({
      value: e.detail,
    });
  },
  onSearch() {
    this.goSearch();
  },
  onClick() {
    this.goSearch();
  },
  goSearch(){
    if(!app.globalData.permission){
      this.setData({
        show: true
      })
       return;
    }
    this.data.hosList = [];
    var This = this;
    var key = this.data.value;
    if(key == ''){
      wx.showToast({
        title: "请输入关键字",
        icon: 'loading',
        duration: 1000
      })
      return false;
    }
    var category = wx.getStorageSync('category');
    var s = category.id;
    var hosList = wx.getStorage({
      //key: 'q_'+s,
      key: 'q'+s,
      success: function (res){
        if(key == ''){
             This.setData({
               hosList:res.data
             })
             return;
        }
        var arr = []; //临时数据
        for(let i in res.data){
            if(res.data[i].question.indexOf(key) >=0){
              var question_title = res.data[i].question;
              question_title = question_title;
              res.data[i].question = question_title;
              arr.push(res.data[i]);
            }
        }
        if(arr.length == 0){
          console.log("===无搜索结果");
          This.setData({
            hosList: []
          })
        }else{
          This.setData({
            hosList: arr
          })
        }
      }
    })
  },
  goquestion: function (t) {
    wx.navigateTo({
      url: "../errorstar/errorstar?ids="+ t.currentTarget.dataset.ids+"&title=题目详情&navtitle=题目详情&cateName=其他" 
    })
  },
});